package arcane.object.game.spell;

import java.awt.Graphics2D;
import java.io.IOException;
import java.util.zip.DataFormatException;

import org.jibx.runtime.JiBXException;

import ps.io.JibxIO;
import ps.object.particle.ParticleSystemManager;

import com.golden.gamedev.object.Sprite;

public class Spell extends Sprite {
	String partSysPath;
	private static JibxIO jibxIO = new JibxIO(ParticleSystemManager.class);
	ParticleSystemManager manager;

	int healthCost, manaCost;

	public Spell() {
		this("");
	}

	public Spell(String sysManagerPath) {
		this.partSysPath = sysManagerPath;
	}

	public void setHealthCost(int healthCost) {
		this.healthCost = healthCost;
	}

	public void setManaCost(int manaCost) {
		this.manaCost = manaCost;
	}

	public int getHealthCost() {
		return healthCost;
	}

	public int getManaCost() {
		return manaCost;
	}

	public void setSystemManager(ParticleSystemManager man, String path) {
		partSysPath = path;
		manager = man;
	}

	public ParticleSystemManager getSystemManager() {
		return manager;
	}

	public String getSystemManagerPath() {
		return partSysPath;
	}

	public void loadSystem() throws JiBXException, DataFormatException,
			IOException {
		manager = jibxIO.loadManager(partSysPath);
	}

	public void setActive(boolean active) {
		manager.setActive(active);
	}

	public boolean isActive() {
		return manager.isActive();
	}

	public void update(long time) {
		if (manager.isActive()) {
			super.update(time);
			manager.update(time);
		}
	}

	public void render(Graphics2D g) {
		manager.render(g);
	}
}